# Makefile for httpserver
# (C) Ramsey Kant 2011-2012

CC := g++
SRCDIR := myhttpserver
BINDIR := bin
BUILDDIR := build
TARGET := myhttpserver
UNAME := $(shell uname)
FILE := file
ERRORFILENAME := error

# Debug Flags
DEBUGFLAGS := -g3 -O0 -Wall
RTCHECKS := -fmudflap -fstack-check -gnato

# Production Flags
PRODFLAGS := -Wall -O2

ifeq ($(UNAME), Linux)
# Linux Flags
CFLAGS := -std=c++11 -Iinclude/ $(DEBUGFLAGS)
LINK := -lpthread -lkqueue $(DEBUGFLAGS)
else
# OSX / BSD Flags
CFLAGS := -std=c++11 -stdlib=libc++ -Iinclude/ $(DEBUGFLAGS)
LINK := -stdlib=libc++ $(DEBUGFLAGS)
endif
 
 
SRCEXT := cpp
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))

FILES := $(BINDIR)/$(FILE)
ERRORS := $(SRCDIR)/$(ERRORFILENAME)

$(TARGET): $(OBJECTS)
	@mkdir -p $(BINDIR)
	@mkdir -p $(FILES)
	@cp -r $(ERRORS) $(BINDIR)
	@echo " Linking..."; $(CC) $(LINK) $^ -o $(BINDIR)/$(TARGET)
 
$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
	#-p 表示递归创建目录
	@mkdir -p $(BUILDDIR)
	@echo " CC $<"; $(CC) $(CFLAGS) -c -o $@ $<
 
clean:
	@echo " Cleaning..."; rm -r $(BUILDDIR) $(BINDIR) $(BINDIR)/$(TARGET)*
 
.PHONY: clean
